#include <bits/stdc++.h>
using namespace std;
#define ll long long
void mayTheForceBeWithYou(){
int p, seats;
cin >> p >> seats;
vector<int> a(p);
int countl = 0;
int countr = 0;
set<int> x;
for(int i = 0; i<p; i++){
cin >> a[i];
if(a[i] == -1) countl++;
else if(a[i] == -2) countr++;
else x.insert(a[i]);
}
int s = x.size();
int j = 0;
//ignore one type
int ans = min(seats, max(countl + s, countr + s));
//element number j is the pivot point = p
for (int p : x) {
int lf = min(countl + j, p - 1), rf = min(seats - p + 1, countr + s - j);
ans = max(ans, lf + rf);
j++;
}
cout << ans;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int ts = 1;
cin>>ts;
while (ts--){
mayTheForceBeWithYou();
cout<<endl;
}
}
1466C - Canine poetry | 74A - Room Leader |
1333D - Challenges in school №41 | 1475B - New Year's Number |
461A - Appleman and Toastman | 320B - Ping-Pong (Easy Version) |
948A - Protect Sheep | 387A - George and Sleep |
53A - Autocomplete | 1729G - Cut Substrings |
805B - 3-palindrome | 805C - Find Amir |
676C - Vasya and String | 1042B - Vitamins |
1729F - Kirei and the Linear Function | 25D - Roads not only in Berland |
1694A - Creep | 659F - Polycarp and Hay |
1040A - Palindrome Dance | 372A - Counting Kangaroos is Fun |
1396B - Stoned Game | 16A - Flag |
1056A - Determine Line | 670B - Game of Robots |
1418C - Mortal Kombat Tower | 1382B - Sequential Nim |
1272C - Yet Another Broken Keyboard | 808A - Lucky Year |
1245A - Good ol' Numbers Coloring | 58B - Coins |